using System;

namespace GoldStone.Split {
    public static class SplitUtil {
        public static String Split(Splitter splitter, String text) {
            return String.Join(" ", splitter.Split(text));
        }

        public static String Split(Splitter splitter, String text, String delimiter) {
            return Split(splitter, text).Replace(" ", delimiter);
        }

        public static String[] SplitToArrayWithCondition(Splitter splitter, String text, Predicate<WordUnit> condition) {
            WordUnit[] words = Array.FindAll(splitter.SplitWithNatureInfo(text), condition);
            String[] result = new string[words.Length];
            for (int i = 0; i < result.Length; i++) {
                result[i] = words[i].Word;
            }
            return result;
        }

        public static String[] SplitToArrayByNature(Splitter splitter, String text, WordNature nature) {
            return SplitToArrayWithCondition(splitter, text, delegate(WordUnit word) {
                                                                 return word.Nature == nature;
                                                             });
        }

        public static String SplitByNature(Splitter splitter, String text, WordNature nature) {
            return String.Join(" ", SplitToArrayByNature(splitter, text, nature));
        }

        public static String[] SplitToArrayByNatureExcept(Splitter splitter, String text, WordNature nature) {
            return SplitToArrayWithCondition(splitter, text, delegate(WordUnit word) {
                                                                 return word.Nature != nature;
                                                             });
        }

        public static String SplitByNatureExcept(Splitter splitter, String text, WordNature nature) {
            return String.Join(" ", SplitToArrayByNatureExcept(splitter, text, nature));
        }
    }
}